//
//  CDAPIManager.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/7.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "CDAPIManager.h"
#import "CDAFNClient.h"

#define KisSignFlag 1  //控制接口是否加密

#define KgetDefaultCountryApi @"splash/getDefaultCountry"//获取默认国家
#define KsplashApi @"splash/category" //分类菜单接口
#define KcityListApi @"news/district/getlist" //城市列表
#define KcityImageApi @"news/info/getRecoImage" //获取城市推荐图片
#define KNewsListApi @"news/info/getNewsList"  //资讯列表接口
#define KNewsSearchApi @"search/news/get" //资讯模糊搜索接口
#define KNewsDetailApi @"news/info/getDetail" //资讯详情接口

#define KGetTokenApi @"token/getPageToken" //获取token
#define KLoginApi @"user/gateway/login" //登录
#define KThirdLoginApi @"user/gateway/ptlogin"//第三方登录
#define KRegisterApi @"user/gateway/reg" //注册
#define KYanZhengMaApi @"user/gateway/sendCode"//验证码
#define KForgetPasswdApi @""//忘记密码
#define KResetPasswdApi @""//重置密码
#define KEditUserHeadApi @"user/info/editHeadImg"//编辑用户头像
#define KRegisterLastApi @"user/info/editDesc" //注册最后一步
#define KEditUserOtherInfoApi @"user/info/editBasicInfo" //编辑用户的其他信息  邮箱 性别等
#define KBindThirdInfoApi @"user/info/bindPtLogin" //手机号登录后 绑定第三方信息
#define KUpLoadImageApi @"util/upload" //上传图片接口

@implementation CDAPIManager
#pragma mark - 单例
+ (instancetype)sharedManager
{
    static CDAPIManager * shared_manager = nil;
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        shared_manager = [[self alloc] init];
    });
    return shared_manager;
}

/**
 *  请求数据处理方法
 *
 *  @return <#return value description#>
 */

-(void)dataHandle:(id)data andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
//    NSString *str = [NSJSONSerialization returnJsonStrWithObject:data];
//    NSDictionary *dic = [NSJSONSerialization returnObjectWithJsonStr:str];

    if (data == nil) {
        block(data,nil,NO);
        [NSObject showStatusBarErrorStr:@"请求失败"];
        return;
    }
    if ([[data objectForKey:@"status"] integerValue]!=0) {
        NSString *error = [data objectForKey:@"msg"];
        if ([NSString isEmpty:error]) {
            block(data,nil,NO);
            [NSObject showStatusBarErrorStr:@"请求失败"];
        }
        else
        {
            block(data,nil,NO);
            [NSObject showStatusBarErrorStr:error];
        }
        
    }
    else
    {
//        [NSObject showStatusBarSuccessStr:@"请求成功啦！"];
        block(data,nil,YES);
    }
}

/**
 *  正常登录请求
 */
- (void)request_Login_WithParams:(id)params andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block //id 类型data 可以是 字典/数组/model
{

    NSString *path = @"api/login";
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id data, NSError *error)
     {
         
     }];
}
/**
 *  注册请求
 */
- (void)request_Register_WithParams:(id)params andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{

}
/**
 *  获取验证码
 */
- (void)request_CaptchaNeededWithPath:(NSString *)path andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    
}

/**
 *  获取默认国家id接口
 *
 *  @param params <#params description#>
 *  @param flag   <#flag description#>
 *  @param block  <#block description#>
 */

-(void)request_getDefaultCountry_withParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KgetDefaultCountryApi];
    //    NSString *path = KsplashApi;
    
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
     NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
        [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif

}


/**
 *  分类菜单接口
 *
 *  @param params <#params description#>
 *  @param block  <#block description#>
 */
- (void)request_splash_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KsplashApi];
//    NSString *path = KsplashApi;
    
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
     NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理

         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
}
/**
 *  城市图片接口
 *
 *  @param params <#params description#>
 *  @param block  <#block description#>
 */
-(void)request_cityImage_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityImageApi];
    NSLog(@"城市推荐图请求路径为 %@",path);
    CDLog(@"城市推荐图请求路径为 %@",path);
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
     NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理

         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理

         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
}

/**
 *  资讯列表接口
 *
 *  @param params <#params description#>
 *  @param block  <#block description#>
 */
-(void)request_newsList_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KNewsListApi];
    NSLog(@"资讯列表请求路径为 %@",path);
    CDLog(@"资讯列表请求路径为 %@",path);
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
     NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
}
/**
 *  资讯搜索
 *
 *  @param params <#params description#>
 *  @param block  <#block description#>
 */
-(void)request_newsSearch_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KNewsSearchApi];
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
    NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
}
/**
 *  资讯详情
 *
 *  @param params <#params description#>
 *  @param block  <#block description#>
 */
-(void)request_newsDetail_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KNewsDetailApi];
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
     NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
}

/**
 *  城市列表
 */
- (void)request_cityList_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
     NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
}

/**
 *  这个接口不需要 token 签名机制
 *
 *  @param params <#params description#>
 *  @param flag   <#flag description#>
 *  @param block  <#block description#>
 */

-(void)request_unLoginGetToken_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KGetTokenApi];
    
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
}
//
//
///**
// *  手机号登录接口
// */
//-(void)request_Login_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KLoginApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// *  第三方登录
// */
//-(void)request_ThirdLogin_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// *  注册
// */
//-(void)request_Register_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// * 验证码
// */
//-(void)request_SendCode_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// *  忘记密码
// */
//-(void)request_ForgetPasswd_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//
//}
///**
// *  重置密码
// */
//-(void)request_ResetPasswd_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// *  编辑用户头像
// */
//-(void)request_EditUserHead_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// *  注册最后一步 编辑信息
// */
//-(void)request_RegisterLast_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}
///**
// *  编辑用户信息 包括 性别 邮箱
// */
//-(void)request_EditUserOtherInfo_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//
//}
///**
// *  登录后绑定第三方信息
// */
//-(void)request_BindThirdInfo_WithParams:(id)params andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
//{
//    NSString *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KcityListApi];
//#ifdef KisSignFlag
//    //接口参数需要签名
//    Person *_person = [Person sharePerson];
//    NSMutableDictionary *mydic = (NSMutableDictionary *)params;
//    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#else
//    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
//#endif
//}


//所有的接口请求处理
-(void)request_AllHandle_WithParams:(id)params andApiTag:(int)tag andIsSign:(BOOL)flag andBlock:(void (^)(id data, NSError *error,BOOL isSuccess))block
{
//#define KgetDefaultCountryTag 100//获取默认国家
//#define KsplashTag 101 //分类菜单接口
//#define KcityListTag 102 //城市列表
//#define KcityImageTag 103 //获取城市推荐图片
//#define KNewsListTag 104  //资讯列表接口
//#define KNewsSearchTag 105 //资讯模糊搜索接口
//#define KNewsDetailTag 106 //资讯详情接口
//    
//#define KGetTokenTag 107 //获取token
//#define KLoginTag 108 //登录
//#define KThirdLoginTag 109//第三方登录
//#define KRegisterTag 110 //注册
//#define KYanZhengMaTag 111//验证码
//#define KForgetPasswdTag 112//忘记密码
//#define KResetPasswdTag 113//重置密码
//#define KEditUserHeadTag 114//编辑用户头像
//#define KRegisterLastTag 115 //注册最后一步
//#define KEditUserOtherInfoTag 116 //编辑用户的其他信息  邮箱 性别等
//#define KBindThirdInfoTag 117 //手机号登录后 绑定第三方信息
//#define KUpLoadImageTag 118 //上传图片接口
    NSString *apiName;
    switch (tag) {
        case KgetDefaultCountryTag:
        {
            apiName = KgetDefaultCountryApi;
           
        }
            break;
        case KsplashTag:
        {
            apiName = KsplashApi;
        }
            break;
        case KcityListTag:
        {
            apiName = KcityListApi;
        }
            break;
        case KcityImageTag:
        {
            apiName = KcityImageApi;
        }
            break;
        case KNewsListTag:
        {
            apiName = KcityImageApi;
        }
            break;
        case KNewsSearchTag:
        {
            apiName = KNewsSearchApi;
        }
            break;
        case KNewsDetailTag:
        {
            apiName = KNewsDetailApi;
        }
            break;
        case KGetTokenTag:
        {
            apiName = KGetTokenApi;
        }
            break;
        case KLoginTag:
        {
            apiName = KLoginApi;
        }
            break;
        case KThirdLoginTag:
        {
            apiName = KThirdLoginApi;
        }
            break;
        case KRegisterTag:
        {
            apiName = KRegisterApi;
        }
            break;
        case KYanZhengMaTag:
        {
            apiName = KYanZhengMaApi;
        }
            break;
        case KForgetPasswdTag:
        {
            apiName = KForgetPasswdApi;
        }
            break;
        case KResetPasswdTag:
        {
            apiName = KResetPasswdApi;
        }
            break;
        case KEditUserHeadTag:
        {
            apiName = KEditUserHeadApi;
        }
            break;
        case KRegisterLastTag:
        {
            apiName = KRegisterLastApi;
        }
            break;
        case KEditUserOtherInfoTag:
        {
            apiName = KEditUserOtherInfoApi;
        }
            break;
        case KBindThirdInfoTag:
        {
            apiName = KBindThirdInfoApi;
        }
            break;
        case KUpLoadImageTag:
        {
            apiName = KUpLoadImageApi;
        }
            break;
//        case KgetDefaultCountryTag:
//        {
//            
//        }
//            break;
            
        default:
            break;
    }
    
    NSString  *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,apiName];
#ifdef KisSignFlag
    //接口参数需要签名
    Person *_person = [Person sharePerson];
    NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    //    NSMutableDictionary *paramDic = [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:mydic withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#else
    //不需要签名
    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
     {//做数据处理
         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
     }];
    
#endif
    
}

-(void)request_upLoadPhoto_WithParams:(id)params image:(UIImage *)image andIsSign:(BOOL)flag andSuccessBlock:(void (^)(id, NSError *))success failureBlock:(void (^)( NSError *))failure progerssBlock:(void (^)(CGFloat))progress;
{
     NSString  *path = [NSString stringWithFormat:@"%@%@",KbaseURLStr,KUpLoadImageApi];
#ifdef KisSignFlag
    
    Person *_person = [Person sharePerson];
    NSMutableDictionary *mydic = [[NSMutableDictionary alloc] initWithDictionary:params];
    [mydic signDic:mydic andToken:_person.token andSecret:_person.secret];
    
    [[CDAFNClient sharedJsonClient] uploadImage:image path:path name:@"opSendf" params:mydic  successBlock:^(NSURLSessionTask *operation, id responseObject)
    {
        
        success(responseObject,nil);
    
    } failureBlock:^(NSURLSessionTask *operation, NSError *error)
    {
        failure(error);
        
    } progerssBlock:^(CGFloat progressValue)
     {
         progress(progressValue);
         
     }];
    
#else
    //不需要签名
//    [[CDAFNClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post autoShowError:NO andBlock:^(id responsedata, NSError *error)
//     {//做数据处理
//         [[CDAPIManager sharedManager] dataHandle:responsedata andBlock:block];
//     }];
//    
    [[CDAFNClient sharedJsonClient] uploadImage:<#(UIImage *)#> path:<#(NSString *)#> name:<#(NSString *)#> successBlock:<#^(NSURLSessionTask *operation, id responseObject)success#> failureBlock:<#^(NSURLSessionTask *operation, NSError *error)failure#> progerssBlock:<#^(CGFloat progressValue)progress#>];
    
#endif
    
}

-(void)upLoadImageRequest
{
     NSDictionary *tempdic =[[NSDictionary alloc] initWithObjectsAndKeys:@"4",@"type",@"1",@"test",@"opSendf",@"fileName", nil];
    UIImage *image = [UIImage imageNamed:@"1380"];
    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    NSString *urlStr = [NSString stringWithFormat:@"%@",@"http://admin.jjhw.com/util/upload"];
    NSString *fileName = @"test.jpg";
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer =[AFHTTPRequestSerializer serializer];
    manager.responseSerializer =[AFHTTPResponseSerializer serializer];
    // 设置超时时间
    [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
    manager.requestSerializer.timeoutInterval = 15.0f;
    [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
    
    [manager POST:urlStr parameters:tempdic constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
        
         [formData appendPartWithFileData:data name:@"opSendf" fileName:fileName mimeType:@"image/jpeg"];
    
    } progress:^(NSProgress * progress){
        CDLog(@"正在上传图片");
    }
          success:^(NSURLSessionDataTask *task, id responseObject){
          
              CDLog(@"上传图片成功了");
              NSString *str =  [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
              NSDictionary *dic =[NSJSONSerialization returnObjectWithJsonStr:str];
              CDLog(@"%@",dic);
          }
          failure:^(NSURLSessionDataTask *task, NSError *error){
              CDLog(@"上传图片失败了");
          }];
}


@end
